//
//  My_editNickName.m
//  daojiVideo
//
//  Created by tikeios_002 on 2024/5/16.
//

#import "My_editNickName.h"
#import "HWPanModal.h"

@interface My_editNickName ()
@property (weak, nonatomic) IBOutlet YBTextFild *nickName;
@property (weak, nonatomic) IBOutlet UIView *footView;
@property (weak, nonatomic) IBOutlet UILabel *nav_title;
@property (weak, nonatomic) IBOutlet UIButton *nav_close;
@property (weak, nonatomic) IBOutlet UIButton *nav_save;

@end

@implementation My_editNickName

-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    self.footView.backgroundColor = viewback_black;
    self.footView.layer.cornerRadius = 18;
    self.footView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
    self.nickName.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入昵称" attributes:@{NSForegroundColorAttributeName:COLOR_ALPH(255, 255, 255, 0.7),NSFontAttributeName:[UIFont systemFontOfSize:14]}];
    self.nickName.maxLength = 10;
    [self.nickName addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventEditingChanged];
    self.nickName.text = [QZUserInfoModel share].nickname;
    [self.nav_close setTitle:NSLocalizedString(@"取消", nil) forState:UIControlStateNormal];
    [self.nav_save setTitle:NSLocalizedString(@"保存", nil) forState:UIControlStateNormal];
    self.nav_title.text = NSLocalizedString(@"昵称", nil);
}
- (void)textChange:(UITextField *)text{
    if (text.markedTextRange != nil) {
        return; //预输入拼音
    }
    if(self.nav_save.userInteractionEnabled == NO){
        self.nav_save.userInteractionEnabled = YES;
        self.nav_save.alpha = 1;
    }
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.nickName becomeFirstResponder];
}

- (IBAction)closeClick:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)saveClick:(id)sender {
    if(self.nickName.text.length == 0){
        [YBMsgPop showPop:NSLocalizedString(@"请输入昵称", nil)];
    }
    [self.nickName resignFirstResponder];
    KMutableDic(sendDic)
    KWeakSelf
    [sendDic setObject:self.nickName.text forKey:@"value"];
    [sendDic setObject:@"nickname" forKey:@"key"];
    [YBNetBase userEditInfoRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            [[QZUserInfoModel share] setValuesForKeysWithDictionary:data];
            [weakSelf dismissViewControllerAnimated:YES completion:nil];
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
#pragma mark - HWPanModalPresentable
- (PanModalHeight)longFormHeight {
    return PanModalHeightMake(PanModalHeightTypeMax, 0);
}

- (HWBackgroundConfig *)backgroundConfig{
    HWBackgroundConfig *config = [HWBackgroundConfig new];
    config.backgroundAlpha = 0.7;
    return config;
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (CGFloat)cornerRadius{
    return 12.0;
}

- (CGFloat)topOffset{
    return 0;
}

- (PanModalHeight)shortFormHeight {
    return [self longFormHeight];
}

- (BOOL)isAutoHandleKeyboardEnabled{
    return NO;
}

- (BOOL)showDragIndicator {
    return NO;
}
@end
